{php $bootstrap_type = 3;}
{template 'header'}
<link type="text/css" rel="stylesheet" href="./source/modules/shopping/images/style.css">
<div class="head">
	<a href="javascript:history.back();" class="bn pull-left"><i class="icon-angle-left"></i></a>
	<span class="title">结算</span>
	<a href="{php echo $this->createMobileUrl('mycart')}" class="bn pull-right"><i class="icon-shopping-cart"></i><span class="buy-num img-circle"> {$carttotal} </span></a>
</div>
<form class="form-horizontal" method="post" role="form" onsubmit='return check()'>
<input type="hidden" name="goodstype" value="{$goodstype}" />
<input type="hidden" name="address" value="{$row['id']}" />
<div class="order-main">
	<h5>收货地址</h5>
	<div id="myaddress"> 
            {if !empty($row)}
	  <div id='address_{$row['id']}' class="shopcart-main img-rounded address_item" style='margin:0;padding:10px;margin-bottom:10px;cursor:pointer' onclick='changeAddress()'>
	 <span>{$row['province']} {$row['city']} {$row['area']} {$row['address']} <br/> {$row['realname']}, {$row['mobile']}</span>
              <span style='float:right'>
                  &nbsp;&nbsp;<a href="{php echo $this->createMobileUrl('address',array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}">管理收货地址</a></span>
	</div>
            {else}
            <div><button type="button" class="btn btn-danger" onclick="location.href='{php echo $this->createMobileUrl('address',array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}'"><i class="icon-plus"></i> 添加修改地址</button></div>
            {/if}
        </div>
 	<h5>配送方式</h5>
	<select id='dispatch' name="dispatch" class="form-control">
            
                        {loop $dispatch $d}
                          <option value="{$d['id']}" price='{$d['price']}'>{$d['dispatchname']} ({$d['price']}元)</option>
                        {/loop}
                         
	</select>
	<h5>订单详情</h5>
	<div class="order-detail">
		<table class="table">
			<thead>
				<tr>
					<th class="name">商品</th>
					<th class="num">数量</th>
					<th class="total">合计</th>
				</tr>
			</thead>
			<tbody>
				{loop $allgoods $item}
				 
                              
				<tr>
                                    <td class="name"><span  style="float:left;"><a href='{php echo $this->createMobileUrl('detail',array('id'=>$item['id']))}'>
                                                                                   {$item['title']}         </a>
                                            {if !empty($item['optionname'])}<br/><span style='font-size:12px;color:#666'> {$item['optionname']}</span>{/if}
                               </span></td>
					<td class="num">{$item['total']}{if !empty($item['unit'])}{$item['unit']}{/if}</td>
                                                            <td class="total"><span class='goodsprice'>{$item['totalprice']} 元</span></td>
				</tr>
				{/loop}
			</tbody>
		</table>
            <div class="order-detail-hd"> <span class="pull-right" style="color:#E74C3C;">
                    [合计：<span id='totalprice'>{$totalprice}</span>]</span></div>
		<div style="clear:both;"></div>
	</div>
	 
	<h5>留言</h5>
	<div class="message-box">
		<textarea class="form-control" rows="3" name="remark" placeholder="亲，还用什么能帮助到您吗？就写到这里吧！"></textarea>
	</div>
	<button type="submit" name="submit" value="yes" class="btn btn-success order-submit btn-lg" style="margin-bottom:20px;">提交订单</button>
	<input type="hidden" name="token" value="{$_W['token']}" />
</div>
        <script language='javascript'>
            function changeAddress(){
                location.href = '{php echo $this->createMobileUrl('address', array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}'
            }
            function check(){
                if((".address_item").length<=0){
                    alert("请添加收货地址!");
                    return false;
                }
                return true;
            }
            $("#dispatch").change(canculate);
            function canculate(){
                var price = 0;
                $(".goodsprice").each(function(){
                    price+=parseFloat($(this).html());
                });
                var dispatchprice = parseFloat($("#dispatch").find("option:selected").attr("price"));
                if(dispatchprice>0){
                   $("#totalprice").html(price + dispatchprice + " 元 (含运费"+dispatchprice + ")");    
                }
                else{
                    $("#totalprice").html(price + " 元");    
                }
                
            }
            $(function(){
                canculate();
            })
            </script>
            
{template 'footer'}
{template 'footerbar'}